<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<jsp:include page="../include/header.jsp"></jsp:include>
<div class="wrap-content">
  <div class="container-fluid">
	   <div class="row">
		   <div class="col-sm-4 p-l-0 p-r-0">
		      <div class="panel panel-default m-b-0">
				    <div class="panel-tabs-wrap">
				         <div class="panel-heading p-0">
							<div class="panel-tabs-tab">
								<ul class="nav nav-tabs ui-widget-header" role="tablist">
									<li class="active"><a href="#role-tab" role="presentation" data-toggle="tab">角色</a></li>
									<li><a href="#user-tab" role="presentation" data-toggle="tab">用户</a></li>
									<li><a href="#org-tab" role="presentation" data-toggle="tab">组织机构</a></li>
								</ul>
							</div>
						</div>
						<div class="panel-body p-0">
							<div class="tab-content panel-tab-content bg-color-white auth-config">
							  	<div role="tabpanel" class="tab-pane active" id="role-tab">
							  	   <div id="role-jqGrid">
								  	   <table id="roleListJqGrid"></table>
								  	   <div id="roleListJqGridPager"></div>
							  	   </div>
								</div>
								<div role="tabpanel" class="tab-pane" id="user-tab">
								   <div id="user-jqGrid">
								  	   <table id="userListJqGrid"></table>
								  	   <div id="userListJqGridPager"></div>
							  	   </div>
								</div>
								<div role="tabpanel" class="tab-pane" id="org-tab">
							  	   <div id="org-jqGrid">
								  	   <table id="orgListJqGrid"></table>
								  	   <div id="orgListJqGridPager"></div>
							  	   </div>
								</div>
							</div>
						</div>
					</div>
				</div><!-- panel -->
			</div><!-- col -->
			<div class="col-sm-8 p-l-5 p-r-0">
			    <div id="has-auth-list">
			       <div class="panel panel-default m-b-0">
			        <div class="panel-heading ui-widget-header" id="has-config-title">已拥有的权限</div>
			        <div class="panel-body p-b-0">
			           <div class="has-config mix-auto-limit-height" id="has-config-wrap"></div>
			        </div>
			    </div>
			  </div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
   $(function(){
	   var leftW = $(".col-sm-4").width()-5;
	   console.log("左宽度",leftW);
	   initRoleList(leftW);
	   initUserList(leftW);
	   initOrgList(leftW);
   });
   
   /**
    * 初始化角色列表
    */
   function initRoleList(width) {
	   $("#roleListJqGrid").jqGridUtils({
			"url":"jqGrid/queryPage/role_simple_list.do",
			"colModel":[{label: "ID",name: "id", hidden:true, key:true},
			            {label: "名称" ,name: "name"}],
			"gridview":true,
			"rowNum":${pageSize},
			offset:39,
			tableStyle:"table table-bordered",
			"scrollrows":true,
			multiselect: false,
			"datatype":"json",
			"pager":"#roleListJqGridPager",
			onSelectRow: function(id, stat, e){
				console.log("选中数据ID：", id);
				var rowData = $("#roleListJqGrid").jqGrid('getRowData',id);
				//console.log("数据：", rowData);
				$("#has-config-title").html("拥有【"+rowData.name+"】的用户或部门");
				mixsmart.loadUri("#has-config-wrap", "auth/inRole.do?roleId="+id, true, false);
				
			}
		});
	   $("#roleListJqGrid").jqGrid('navGrid','#roleListJqGridPager',{add:false, edit:false, del:false, view:false, search:false});
   }
   
   /**
    * 初始化用户列表
    */
   function initUserList(width) {
	   $("#userListJqGrid").jqGridUtils({
			"url":"jqGrid/queryPage/user_simple_list.do",
			"colModel":[{label: "ID", name: "id", hidden:true, key:true},
			            {label: "名称", name: "name"},
			            {label: "所在部门", name: "orgName"}],
			"gridview":true,
			"rowNum":${pageSize},
			offset:39,
			autowidth:false,
			width:width,
			tableStyle:"table table-bordered",
			"scrollrows":true,
			multiselect: false,
			"datatype":"json",
			"pager":"#userListJqGridPager"
		});
	   $("#userListJqGrid").jqGrid('navGrid','#userListJqGridPager',{add:false, edit:false, del:false, view:false, search:false});
   }
   
   /**
    * 初始化组织机构列表
    */ 
   function initOrgList(width) {
	   $("#orgListJqGrid").jqGridUtils({
			"url":"jqGrid/queryTree/org_simple_list.do",
			"colModel":[{label: "ID",name: "id", hidden:true, key:true},
			            {label: "名称" ,name: "orgName"},
			            {label: "类型" ,name: "orgType"}],
			offset:39,
			"gridview":true,
			"rowNum":10000,
			tableStyle:"table table-bordered",
			"scrollrows":true,
			"treeGrid":true,
			"ExpandColumn":"orgName",
			"ExpandColClick" : true,
			"treeGridModel":"adjacency",
			"datatype":"json",
			"pager":"#orgListJqGridPager",
			onSelectRow:function(id, stat, e){
				alert(id);
			}
		});
	   $("#orgListJqGrid").jqGrid('navGrid','#orgListJqGridPager',{add:false, edit:false, del:false, view:false, search:false});
   }
</script>
<jsp:include page="../include/footer.jsp"></jsp:include>